<template>
	<div>
		<h2 class="title">编辑公告</h2>
		<el-form label-width="100px" style="max-width: 750px" label-position="top">
			<el-row :gutter="20">
				<el-col :span="10" :offset="8">
					<el-form-item label="发布人">
						<el-input v-model="noticeInfo.noticePerson" />
					</el-form-item>
					<el-form-item label="公告楼栋">
						<el-input type="text" resize="none" v-model.number="noticeInfo.buildId" />
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="20">
				<el-col :span="10" :offset="8">
					<el-form-item label="公告内容">
						<el-input
							v-model.trim="noticeInfo.noticeContent"
							type="textarea"
							resize="none"
							:autosize="{ minRows: 2, maxRows: 6 }" />
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<el-row :gutter="20">
			<el-col :span="10" :offset="14">
				<el-button type="primary" plain @click="createNotice">发布</el-button>
			</el-col>
		</el-row>
	</div>
</template>

<script setup>
import { reactive } from 'vue'
import { useUserStore } from '@/stores/userStore'
import { addNoticeByHou } from '@/utils/axios/domiRequests'

const { userInfo } = useUserStore()
const noticeInfo = reactive({
	noticePerson: userInfo.houName,
	noticeContent: '',
	buildId: userInfo.buildId,
})

function createNotice() {
	noticeInfo.buildId=Number.parseInt(noticeInfo.buildId)
	addNoticeByHou(noticeInfo).then(() => {
		Object.assign(noticeInfo, { noticeContent: '' })
	})
}
</script>

<style scoped lang="sass"></style>
